module.exports = (sequelize, DataTypes) => {
    const user = sequelize.import('./user.model')

    const employee = sequelize.define('employee', {
      uid: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
      department: {
        type: DataTypes.STRING,
        allowNull: true
      },
      is_admin: {
        type: DataTypes.STRING,
        allowNull: false,
        defaultValue:'否'
      },
      is_approved: {
        type: DataTypes.STRING,
        allowNull: false,
        defaultValue:'未审核'
      },
      real_name:{
          type:DataTypes.STRING,
          allowNull:false
      }
    },{
        timestamps:false,
        tableName:'employee'
    })

    employee.belongsTo(user, {
      foreignKey: 'uid',
      sourceKey: 'uid',
      onUpdate: 'CASCADE',
      onDelete: 'CASCADE'
    })
    user.hasOne(employee,{
        foreignKey: 'uid',
        sourceKey: 'uid',
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE'
    })
    // employee.afterCreate(async (employee) => {
    //   await employee.update({
    //     uid: user.uid,
    //   },{where:{
    //       real_name:user.real_name
    //       }})
    // })
    // employee.beforeDestroy(async (employee) => {
    //   await user.destroy({
    //     where: {
    //       uid: employee.uid
    //     }
    //   })
    // })
    return employee
  }
